/**
 * 
 */
package GUI.GameLoadWindowPackage;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JButton;
import javax.swing.JColorChooser;

import Utils.Utils;

/**
 * @author Avia Tam
 * @author Assaf Miron
 *
 */
@SuppressWarnings("serial")
class ColorButton extends JButton {

    private Integer index;
    private Color color;
    private Component parent;

    ColorButton(Component panel, Integer i) {
	super();
	parent = panel;
	index = i;
	// Get a Random Color
	setColor(Utils.getRandomColor());

    }

    Integer getIndex() {
	return index;
    }

    Color getColor() {
	return color;
    }

    void setColor(Color color) {
	this.color = color;
	// Set the Color for the Button
	setBackground(color);
    }

    /**
     * Returns the Selected Color from a Color Chooser
     * @return The Selected Color
     */
    @SuppressWarnings("static-access")
    protected void getPlayerColor() {
	color = new JColorChooser().showDialog(parent, "Choose the Player Color", Color.black);
	// Make sure that a Color is Selected
	if (color == null) {
	    color = Utils.getRandomColor();
	}
	// Set the Color for the Button
	setBackground(color);
    }
}
